import React from 'react';
import { Modal } from 'antd';
import './index.less';

export default class Dialog extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      isModalVisible: false,
    };
  }
  setIsModalVisible = (bol) => {
    this.setState({
      isModalVisible: bol,
    });
  };
  handleOk = () => {
    const { onOk = null } = this.props;
    if (onOk && typeof onOk == 'function') {
      onOk();
      return;
    }
    this.setIsModalVisible(false);
  };

  handleCancel = () => {
    const { onCancel = null } = this.props;
    if (onCancel && typeof onCancel == 'function') {
      onCancel();
      return;
    }
    this.setIsModalVisible(false);
  };
  render() {
    const { isModalVisible } = this.state;
    const { children = null, otherProps, extendProps } = this.props;
    return (
      <React.Fragment>
        <Modal
          {...otherProps}
          {...extendProps}
          visible={isModalVisible}
          onOk={this.handleOk}
          onCancel={this.handleCancel}
        >
          {children}
        </Modal>
      </React.Fragment>
    );
  }
}
